package com.mrjy.common.qtz;

import javax.annotation.Resource;

import org.apache.log4j.Logger;

import com.mrjy.wechat.bo.IWeChatOAuthBo;
import com.mrjy.wechat.conts.WxConsts;
import com.mrjy.wechat.process.AccessToken;
import com.mrjy.wechat.process.JSTicket;

public class AccessTokenAndJSTicketJob{
	
	@Resource
	private IWeChatOAuthBo weChatOAuthBo;
	
    private static Logger logger = Logger.getLogger(AccessTokenAndJSTicketJob.class);
    /**
     * @Description: 任务执行获取 token
     * @param    
     */
    public void getTokenAndTicket() {
    	/**
    	 * 说明：已在获取accessToken和js_ticket的方法中全局缓存了，这里取消全局缓存
    	 */
    	AccessToken accessToken = weChatOAuthBo.getAccessToken(WxConsts.APPID, WxConsts.APPSECRET);
        if (null != accessToken) {
			/*
			 *全局缓存access_token
			 */
        	/*ServletContext sc = ServletContextUtil.get();
        	sc.removeAttribute(WxConsts.ACCESS_TOKEN);
        	sc.setAttribute(WxConsts.ACCESS_TOKEN, accessToken);*/
        	
        	/*
        	 * 全局缓存js_ticket 
        	 */
        	/*JSTicket js_ticket = weChatOAuthBo.getJsapiTicket(accessToken);
        	sc.removeAttribute(WxConsts.JS_TICKET);
        	sc.setAttribute(WxConsts.JS_TICKET, js_ticket);*/
        	
        	JSTicket js_ticket = weChatOAuthBo.getJsapiTicket(accessToken);
        	logger.info("----------------------->accessToken:" + accessToken.getAccessToken() + ", ---------js_ticket:" + js_ticket.getTicket());
		}else {
			logger.error("定时器，定时获取token失败 ");  
		}
    }

}